/**
 * @file   openglrenderer.h
 * @Author Alexandre Chassany (alexandre.chassany@gmail.com)
 * @date   March 2011
 * @brief  OpenGL implementation of the renderer interface
 *
 * Poum-tchak is a free sound manipulation and synthesis, 
 * real-time and interactive music-clip rendering.
 *
 * Copyright (C) 2011  Chassany Alexandre and Gonzalez Antoine.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * he Free Software Foundation, either version 3 of the License, or
 * at your option) any later version.
 *
 * is program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef _ELIXIR_OPENGLRENDERER_H
#define _ELIXIR_OPENGLRENDERER_H

#include <renderer/irenderer.h>
#include <core/singleton.h>
#include <renderer/impl/opengl/openglbuffer.h>
#include <renderer/impl/opengl/opengldeclaration.h>

namespace Elixir
{

  class OpenGLRenderer : public Singleton<OpenGLRenderer>, public IRenderer
  {
  public :

	/// Singleton 
	friend class Singleton<OpenGLRenderer>;

	/// IRenderer interface implementation. @see IRenderer class for more
	/// informations.
	virtual void initialize();
	virtual void beginScene()const;
	virtual void endScene()const;

	virtual IBufferBase* createVB(unsigned long size, unsigned long stride, unsigned long flags) const;
	virtual IBufferBase* createIB(unsigned long size, unsigned long stride, unsigned long flags) const;
	virtual IDeclaration* createDeclaration(const DeclarationElement* elements, std::size_t count) const;
	virtual void setVB(unsigned int stream, const IBufferBase* buffer, unsigned long stride, unsigned long min_vertex, unsigned long max_vertex);
	virtual void setIB(const IBufferBase* buffer, unsigned long stride);
	virtual void setDeclaration(const IDeclaration* declaration);
					   
	virtual void drawPrimitives(PrimitiveType type, unsigned long firstVertex, unsigned long count) const;
	virtual void drawIndexedPrimitives(PrimitiveType type, unsigned long firstIndex, unsigned long count) const;
	
  private:
	OpenGLRenderer();
	virtual ~OpenGLRenderer();
	
	const OpenGLDeclaration* currentDeclaration_; ///< Declaration courante
	unsigned long          indexStride_;        ///< Taille courante des indices
  }; 
}


#endif // _ELIXIR_OPENGLRENDERER_H
